<?php

/*
	info: 个人中心
*/

require dirname(__FILE__).'/include/common.inc.php';

//修改密码
if ($webglobal['action']=='chgpass')
{
	if ($webglobal['doit']==1)
	{
		global_CheckPost(
					array(
						array('oldpassword','str','','原密码输入错误',1),
						array('newpassword','password','','新密码不能少于6位',1),
						array('newpassword2','password','','',0,''),
				));
		if (empty($webglobal['CPM']))
		{
			if (md5($webglobal['CPP']['oldpassword']) != $user['password'])
			{
				$webglobal['CPM'][] = '原密码输入错误';
			}
			if ($webglobal['CPP']['newpassword'] != $webglobal['CPP']['newpassword2'])
			{
				$webglobal['CPM'][] = '两次新密码输入不一致';
			}
		}
		//json格式判断
		if ($webrequest['pagehead']=='ajax')
		{
			if (!empty($webglobal['CPM']))
			{
				echo '{"status":0,"errorinfo":"'.implode('<br />', $webglobal['CPM']).'"}';
			}
			else
			{
				echo '{"status":1}';
			}
			exit();
		}
		if (!empty($webglobal['CPM']))
		{
			global_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			$tempnewpassword = md5($webglobal['CPP']['newpassword']);
			$db->Update('adminuser', "password='{$tempnewpassword}'", "id='{$user['uid']}'");
			$objuser->SetUserCookie($user['username'], $tempnewpassword);
			global_ShowMessage('密码修改成功。', WEBURLPATH."/{$webserver['curfilename']}.php?action={$webglobal['action']}");
		}
	}
}

template_Display($webserver['curfilename']);
